'use strict';
//我的佣金
import React,{Component} from 'react';
import Header from '../../common/header';
import * as URLconstant from '../../constant/URLconstant'
import Util from '../../common/util';
import CommissionList from './commissionList';
import CashOutList from './cashOutList';//已提现列表
import {
    View,
    Text,
    TouchableOpacity,
    Image,
    StyleSheet,
    ScrollView
} from 'react-native';
export default class myCommission extends Component{
    // 构造
      constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            commissionData:null
        };
      }

    componentDidMount() {
        this.getCommission()
    }

      getCommission(){
          let url  = URLconstant.MY_COMMISSION
          let datakey=[]
          datakey['user_id']=this.props.user_id
          if(this.props.income_type){
              datakey['income_type']=this.props.income_type
          }
          Util.get(url,datakey,this.getCommissionSuc.bind(this),this.errorCallback.bind(this))
      }

    getCommissionSuc(datas){
        if(datas.status==0){
            this.setState({
                commissionData:datas.data
            })
        }
    }

    errorCallback(err){

    }

    linkJump(jump,type){
          this.props.navigator.push({
              component:jump,
              passProps:{
                  user_id:this.props.user_id,
                  type:type
              }
          })
    }

      render(){
          let commissionData = this.state.commissionData
          return(
              <View style={{flex:1,backgroundColor:"#f0f0f0"}}>
                  <Header navigator={this.props.navigator} initObj={{ title: '我的佣金',id:2}}/>
                  {
                      commissionData==null?
                          <View style={{flex:1}}>
                              {Util.loading()}
                          </View>
                          :
                          <View style={{flex:1}}>
                              <TouchableOpacity onPress={()=>this.linkJump(CommissionList,'no')} style={styles.income_view}>
                                <Text style={{fontSize:16,color:"#fff",marginBottom:10}}>佣金余额</Text>
                                <Text style={{fontSize:30,color:"#fff"}}>¥{commissionData.usable_income}</Text>
                              </TouchableOpacity>
                              <View style={styles.wrap_view}>
                                  <TouchableOpacity onPress={()=>this.linkJump(CommissionList,'yes')} style={styles.view_item}>
                                    <View style={styles.item_left}>
                                        <Text style={{fontSize:14,color:"#333",marginBottom:5}}>待完成</Text>
                                        <Text style={{fontSize:12,color:"#969696"}}>还处于退换货确认期内的佣金</Text>
                                    </View>
                                      <Text style={{fontSize:18,color:"#DD575C"}}>¥{commissionData.total_income_vm}</Text>
                                  </TouchableOpacity>
                                  <TouchableOpacity onPress={()=>this.linkJump(CashOutList)} style={styles.view_item}>
                                      <View style={styles.item_left}>
                                          <Text style={{fontSize:14,color:"#333",marginBottom:5}}>已提现</Text>
                                          <Text style={{fontSize:12,color:"#969696"}}>已提现的佣金</Text>
                                      </View>
                                      <Text style={{fontSize:18,color:"#DD575C"}}>¥{commissionData.user_income}</Text>
                                  </TouchableOpacity>
                                  <View style={styles.view_item}>
                                      <View style={styles.item_left}>
                                          <Text style={{fontSize:14,color:"#333",marginBottom:5}}>历史总收益</Text>
                                          <Text style={{fontSize:12,color:"#969696"}}>历史总收益情况</Text>
                                      </View>
                                      <Text style={{fontSize:18,color:"#DD575C"}}>¥{commissionData.total_income}</Text>
                                  </View>
                              </View>
                          </View>
                  }
              </View>
          )
      }
}
var styles = StyleSheet.create({
    income_view:{
        backgroundColor:"#f65061",
        height:150,
        alignItems:'center',
        justifyContent:'center'
    },
    wrap_view:{
        backgroundColor:"#fff",
        paddingHorizontal:10,
    },
    view_item:{
        flexDirection:'row',
        alignItems:'center',
        height:60,
        justifyContent:'space-between',
        borderBottomWidth:1,
        borderBottomColor:"#e0e0e0"
    }
})